package com.ease.framework.gef4p.commands {
   import com.ease.framework.gef.EditPart;
   import com.ease.framework.gef.IEditor;
   import com.ease.framework.gef4p.model.Vertex;
   import com.ease.framework.workbench.Workbench;
   import com.ease.framework.workbench.spi.impls.Command;

   import flash.geom.Point;

   /**
    * 执行Move和Resize的Command.
    */
   public class MoveResizeVertexCommand extends Command {
      private var vertex:Vertex;

      private var originalPosition:Point;
      private var originalRectangle:Point;

      private var newPointGAP_x:Number = 0;
      private var newPointGAP_y:Number = 0;
      private var newPointGAP_width:Number = 0;
      private var newPointGAP_height:Number = 0;

      public function MoveResizeVertexCommand(obj:Vertex, gap_x:Number, gap_y:Number, gap_width:Number, gap_height:Number) {
         super();
         vertex = obj;
         originalPosition = new Point(vertex.x, vertex.y);
         originalRectangle = new Point(vertex.width, vertex.height);

         newPointGAP_x = gap_x;
         newPointGAP_y = gap_y;
         newPointGAP_width = gap_width;
         newPointGAP_height = gap_height;
      }

      override public function execute():void {
         vertex.x = originalPosition.x + newPointGAP_x;
         vertex.y = originalPosition.y + newPointGAP_y;
         if (vertex.x < 1)
            vertex.x = 1;
         if (vertex.y < 1)
            vertex.y = 1;

         vertex.width = originalRectangle.x + newPointGAP_width;
         vertex.height = originalRectangle.y + newPointGAP_height;

         var activityEditPart:EditPart = IEditor(Workbench.instance.currentEditor).getEditDomain().getEditPartByModel(vertex) as EditPart;
         activityEditPart.refreashFigure();
      }

      override public function undo():void {
         vertex.x = originalPosition.x;
         vertex.y = originalPosition.y;
         vertex.width = originalRectangle.x;
         vertex.height = originalRectangle.y;

         var activityEditPart:EditPart = IEditor(Workbench.instance.currentEditor).getEditDomain().getEditPartByModel(vertex) as EditPart;
         activityEditPart.refreashFigure();
      }
   }
}